<template>
  <div>
    <el-table v-loading="value.loading" :data="value.data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50" />
      <slot />
      <el-table-column label="操作" align="center" width="260">
        <template #default="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="$emit('handleView', scope.row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <Pagination v-show="value.total > 0"
                :total="value.total"
                :page.sync="value.queryParams.pageNum"
                :limit.sync="value.queryParams.pageSize"
                @pagination="$emit('getList')" />
  </div>
</template>

<script>
import Pagination from './components/Pagination.vue'
export default {
  components: { Pagination },
  props: {
    value: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ['handleView', 'getList', 'input'],
  methods: {
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.$emit('input', {
        ...this.value,
        ids: selection.map(item => item.id)
      })
      this.$emit('input', {
        ...this.value,
        single: selection.length !== 1
      })
      this.$emit('input', {
        ...this.value,
        multiple: !selection.length
      })
    }
  }
}
</script>
